package com.kaishengit.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.kaishengit.pojo.Goal;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.Task;
import com.kaishengit.pojo.User;

@Repository
public class GoalDao extends BaseDao<Goal, String>{

	@Override
	public List<Goal> findAll() {
		String hql = "from Goal";
		Query query = getSession().createQuery(hql);
		@SuppressWarnings("unchecked")
		List<Goal> goalList=query.list();
		
		return goalList;
	}

	public List<Goal> findAllByPro(Project project) {
		String hql = "from Goal where projectid = :id order by createtime desc";
		Query query = getSession().createQuery(hql);
		query.setParameter("id", project);
		@SuppressWarnings("unchecked")
		List<Goal> goalList=query.list();
		
		return goalList;
	}

	public List<Goal> findByUser(User user) {
		String hql="from Goal where user=:user order by createtime desc";
		Query query=getSession().createQuery(hql);
		query.setParameter("user", user);
		@SuppressWarnings("unchecked")
		List<Goal> goalList=query.list();
		return goalList;
	}
	
}
